<template>
  <view class="post-form">
    <input v-model="title" placeholder="输入标题" />
    <textarea v-model="body" placeholder="输入内容"></textarea>
    <button @click="submitPost">发布</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      title: '',
      body: ''
    };
  },
  methods: {
    submitPost() {
      if (this.title && this.body) {
        const newPost = { title: this.title, body: this.body, likes: 0 };
        console.log("发布帖子", newPost);
        // 这里可以将新帖子保存到数据库或本地存储
        uni.navigateBack(); // 返回上一页
      } else {
        uni.showToast({ title: "标题和内容不能为空", icon: "none" });
      }
    }
  }
};
</script>

<style scoped>
.post-form {
  padding: 20px;
}

input, textarea {
  width: 100%;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

button {
  background-color: #3f8fe0;
  color: white;
  border-radius: 5px;
  padding: 10px 15px;
  margin-top: 10px;
}
</style>
